# src/data/structures.py
from dataclasses import dataclass, field
from typing import Dict, Any, Optional, Tuple
import numpy as np


@dataclass
class BinocularImagePair:
    """
    双目图像对数据结构

    用于存储左右摄像头采集的图像及相关元数据
    """

    left_image: np.ndarray  # 左摄像头采集的图像, 类型为numpy数组
    right_image: np.ndarray  # 右摄像头采集的图像, 类型为numpy数组
    timestamp: Optional[float] = None  # 图像采集时间戳, float类型, 可选
    metadata: Dict[str, Any] = field(
        default_factory=dict
    )  # 其他元数据信息, 字典类型, 默认空字典

    def validate(self) -> bool:
        """
        检查左右图像是否都存在且尺寸一致

        returns:
            bool: 如果左右图像都存在且尺寸一致, 返回True, 否则返回False
        """
        return (
            self.left_image is not None
            and self.right_image is not None
            and self.left_image.shape == self.right_image.shape
        )


@dataclass
class CalibrationData:
    """标定数据结构"""

    camera_matrix_left: np.ndarray  # 左摄像头的内参矩阵, numpy数组
    camera_matrix_right: np.ndarray  # 右摄像头的内参矩阵, numpy数组
    dist_coeffs_left: np.ndarray  # 左摄像头的畸变系数, numpy数组
    dist_coeffs_right: np.ndarray  # 右摄像头的畸变系数, numpy数组
    rotation_matrix: np.ndarray  # 左右摄像头之间的旋转矩阵, numpy数组
    translation_vector: np.ndarray  # 左右摄像头之间的平移向量, numpy数组
    essential_matrix: np.ndarray  # 本质矩阵, numpy数组
    fundamental_matrix: np.ndarray  # 基础矩阵, numpy数组
    reprojection_error: float = 0.0  # 重投影误差, float类型, 默认0.0
    image_size: Optional[Tuple[int, int]] = (
        None  # 图像尺寸, 格式为(width, height), 可选
    )
